import * as echarts from '../../components/ec-canvas/echarts';
import * as API_Distribution from '../../api/distribution.js'

const app = getApp();

async function initChart(canvas, width, height, dpr) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(chart);

  let res = await API_Distribution.getStatisticsBill()
  let price = res.map(item=>item.price)
  let time = res.map(item=>item.time)
  var option = {
    grid: {
      containLabel: true
    },
    tooltip: {
      show: true,
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: time,
    },
    yAxis: {
      x: 'center',
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      }
    },
    series: [{
      name: '月账单',
      type: 'line',
      data: price,
      markPoint: {
        data:[{
          type: 'max',
          name:"最大值"
        }]
      }
    }]
  };
  chart.setOption(option);
  return chart;
}
async function initChart2(canvas, width, height, dpr) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(chart);

  let res = await API_Distribution.getStatisticsDistribution()
  let price = res.map(item=>item.price)
  let time = res.map(item=>item.time)
  var option = {
    grid: {
      containLabel: true
    },
    tooltip: {
      show: true,
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: time,
    },
    yAxis: {
      x: 'center',
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      }
    },
    series: [{
      name: '月账单',
      type: 'line',
      data: price,
      markPoint: {
        data:[{
          type: 'max',
          name:"最大值"
        }]
      }
    }]
  };
  chart.setOption(option);
  return chart;
}
Page({
  data: {
    ec: {
      onInit: initChart
    },
    ec2: {
      onInit: initChart2
    }
  },

  onReady() {},
  onShow() {

  }
});